﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.BIZ;
using AnyOffice.Model;

namespace AnyOffice.general.report.info
{
    public partial class read_month1 : ModulePage
    {
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ReportCommentDao dao = new ReportCommentDao();
            ReportCommentData data = new ReportCommentData();
            int reportId = Convert.ToInt32(this.ViewState["ReportId"].ToString());
            data.ReportId = reportId;
            data.UserId = base.User.Identity.Name;
            data.SendTime = DateTime.Now;
            data.Content = this.txtContent.Value;
            dao.Insert(base.Conn, data);
            if (this.ckbSms.Checked || this.ckbMobile.Checked)
            {
                DataTable table = new ReportDao().SelectByReportId(base.Conn, reportId);
                if (table.Rows.Count > 0)
                {
                    SmsData data2 = new SmsData();
                    SmsDao dao2 = new SmsDao();
                    data2.Type = 15;
                    data2.FromId = base.User.Identity.Name;
                    data2.ToIdList = table.Rows[0]["UserId"].ToString();
                    data2.Content = new UserCache().UserName + "对您 " + Convert.ToDateTime(table.Rows[0]["ReportTime"].ToString()).ToString("yyyy-MM-dd") + " 的月报“" + table.Rows[0]["Title"].ToString() + "”进行了点评，请查看！";
                    data2.RemindFlag = true;
                    data2.SendTime = DateTime.Now;
                    dao2.BizSend(base.Conn, data2, this.ckbSms.Checked, this.ckbMobile.Checked);
                }
            }
            DataTable table2 = new ReportCommentDao().SelectAll(base.Conn, reportId);
            if (table2.Rows.Count > 0)
            {
                this.rptComment.DataSource = table2;
                this.rptComment.DataBind();
            }
            this.txtContent.Value = string.Empty;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int reportId = (Request.QueryString["report_id"] == null) ? 0 : int.Parse(Request.QueryString["report_id"].ToString());
                this.ViewState["ReportId"] = reportId;
                DataTable table = new ReportDao().SelectByReportId(base.Conn, reportId);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPromptClose("无月报记录");
                }
                else
                {
                    //if (table.Rows[0]["Managers"] != DBNull.Value)
                    //{
                    //    if (("," + table.Rows[0]["Managers"].ToString() + ",").IndexOf("," + base.User.Identity.Name + ",") < 0)
                    //    {
                    //        this.pnlMain.Visible = false;
                    //        this.litMessage.Text = base.ShowPromptClose("无月报记录");
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    this.pnlMain.Visible = false;
                    //    this.litMessage.Text = base.ShowPromptClose("无月报记录");
                    //    return;
                    //}
                    this.litTitle.Text = table.Rows[0]["Title"].ToString();
                    this.litUserName.Text = "<u title=\"部门：" + table.Rows[0]["DeptName"].ToString() + "\" style=\"CURSOR:hand\">" + table.Rows[0]["UserName"].ToString() + "</u>";
                    this.litReportTime.Text = Convert.ToDateTime(table.Rows[0]["ReportTime"].ToString()).ToString("yyyy-MM-dd");
                    if (table.Rows[0]["Note1"] != DBNull.Value)
                    {
                        this.litNote1.Text = table.Rows[0]["Note1"].ToString().Replace("\n", "<br>");
                    }
                    if (table.Rows[0]["Note2"] != DBNull.Value)
                    {
                        this.litNote2.Text = table.Rows[0]["Note2"].ToString().Replace("\n", "<br>");
                    }
                    if (table.Rows[0]["Note3"] != DBNull.Value)
                    {
                        this.litNote3.Text = table.Rows[0]["Note3"].ToString().Replace("\n", "<br>");
                    }
                    //if (table.Rows[0]["Note4"] != DBNull.Value)
                    //{
                    //    this.litNote4.Text = table.Rows[0]["Note4"].ToString().Replace("\n", "<br>");
                    //}
                    if (table.Rows[0]["AttachmentId"] != DBNull.Value)
                    {
                        string attachmentId = table.Rows[0]["AttachmentId"].ToString();
                        if ((this.litAttachment.Text = AttachmentBiz.Display(base.Conn, attachmentId)) != string.Empty)
                        {
                            this.pnlAttachment.Visible = true;
                        }
                        else
                        {
                            this.litAttachment.Text = "无";
                        }
                    }
                    DataTable table2 = new ReportCommentDao().SelectAll(base.Conn, reportId);
                    if (table2.Rows.Count > 0)
                    {
                        this.rptComment.DataSource = table2;
                        this.rptComment.DataBind();
                    }
                    this.btnSubmit.Attributes.Add("onclick", "return CheckForm();");
                    this.ckbMobile.Visible = SmsDao.IsMobile(SmsDao.SmsType.Report);
                }
            }
        }
 

    }
}
